/*
 * AbstractView.java
 *
 * Created on 2008/09/23 +0900
 *
 * $Revision: 38 $
 * $Date: 2008-10-11 08:48:45 +0000 (Sat, 11 Oct 2008) $
 */

package org.gikolet.framework.view;

import org.gikolet.framework.util.Listener;
import org.gikolet.framework.util.ListenerList;
import org.gikolet.framework.util.PropertyListener;

/**
 * @author tetsutaro (latest modification by $Author: tetsutaro.ss $)
 * @version $Revision: 38 $ $Date: 2008-10-11 08:48:45 +0000 (Sat, 11 Oct 2008) $
 */
public abstract class AbstractView implements View {
    private String viewName;

    private ListenerList propertyListenerList;

    public AbstractView() {
	this.propertyListenerList = new ListenerList();
    }

    /**
     * @see org.gikolet.framework.view.View#getViewName()
     */
    public String getViewName() {
	return this.viewName;
    }

    protected void setViewName(String viewName) {
	this.viewName = viewName;

	firePropertyChange(View.PROPERTY_VIEW_NAME);
    }

    public void addPropertyListener(PropertyListener listener) {
	this.propertyListenerList.add(listener);
    }

    public void removePropertyListener(PropertyListener listener) {
	this.propertyListenerList.remove(listener);
    }

    protected void firePropertyChange(String propertyName) {
	Listener[] listeners = this.propertyListenerList.getListeners();

	for (int i = 0; i < listeners.length; i++) {
	    ((PropertyListener) listeners[i]).propertyChanged(this, propertyName);
	}
    }
}
